// 引入接口的请求方法
import { reqGetBannerList, reqFloorList } from '../api'
const state = {
  //轮播图的数据
  bannerList: [],
  //floor组件的数据
  floorList: [],
  // 所有图片数据
  allBannerImg:[]
}
const mutations = {
  GETBANNERLIST(state, params) {
    state.bannerList = params[0].slice(0, 4);//轮播图只展示前面几张图片
    // 暂时将bannerList复制为floorList
    state.floorList = params[0];
    state.allBannerImg = params[1];

  },
  /* GETFLOORLIST(state, floorList) { 
    state.floorList = floorList;
  } */
}
const actions = {
  //获取首页轮播图的数据
  async getBannerList({ commit }, param) {
    let result = await reqGetBannerList();
    // 加载开始先准备一个轮播图
    let firstBannrt = result.data.data[0].bannerImg
    let newBanner = firstBannrt || []
    let allBannerImg = result.data.data;
    result.data.data.filter(item => {
      if (item.bannerType == param) newBanner = item.bannerImg
    })
    if (result.code == 200) {
      commit("GETBANNERLIST", [ newBanner, allBannerImg ]);
    }
  },
/*   //获取首页所有floor的数据
  async getFloorList({ commit }, param) {
    let result = await reqFloorList();
    // 加载开始先准备一个轮播图
    let firstBannrt = result.data.data[0].bannerImg
    let newBanner = firstBannrt || []

    result.data.data.filter(item => {
      if (item.bannerType == param) newBanner = item.bannerImg
    })
    if (result.code == 200) {
      commit("GETFLOORLIST", newBanner);
    }
  }, */
}
const getters = {
}
export default {
  state, mutations, actions, getters
}